package com.yuke.cloud.service.cmc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.api.cmc.dto.CmsCouponGoodsDto;
import com.yuke.cloud.service.cmc.dao.CmsCouponSpecMapper;
import com.yuke.cloud.service.cmc.dto.CmsCouponSpecDto;
import com.yuke.cloud.service.cmc.entity.CmsCouponSpec;
import com.yuke.cloud.service.cmc.service.CmsCouponSpecService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by wg on 2019/09/25.
 */
@Service
@Transactional
public class CmsCouponSpecServiceImpl extends BaseService<CmsCouponSpec> implements CmsCouponSpecService {
    @Resource
    private CmsCouponSpecMapper cmsCouponSpecMapper;


    @Override
    public List<CmsCouponSpecDto> getBindingGoods(CmsCouponSpec cmsCouponSpec) {

        Long couponId = cmsCouponSpec.getCouponId();
        List<CmsCouponSpecDto> bindingGoods = cmsCouponSpecMapper.getBindingGoods(couponId);
        return bindingGoods;
    }

    @Override
    public List<CmsCouponSpecDto> getCouponSpecListByCouponId(@RequestParam(value = "CouponId") Long CouponId){
        Example example = new Example(CmsCouponSpec.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("couponId", CouponId);
        criteria.andEqualTo("status", "0");
        List<CmsCouponSpec> list = cmsCouponSpecMapper.selectByExample(example);

        List<CmsCouponSpecDto> cmsCouponSpecList = new ArrayList<>();

        if (list!=null && list.size()>0){
            for(CmsCouponSpec item : list){
                CmsCouponSpecDto cmsCouponSpecDto = new CmsCouponSpecDto();
                cmsCouponSpecDto.setCouponId(CouponId);
                cmsCouponSpecDto.setSpecId(item.getSpecId());
                cmsCouponSpecList.add(cmsCouponSpecDto);
            }
        }
        return cmsCouponSpecList;
    }

    /**
     * 获取商品绑定选择列表
     * @param
     * @return
     */
    @Override
    public List<CmsCouponSpecDto> getGoodsList(CmsCouponSpecDto cmsCouponSpecDto) {
            List<CmsCouponSpecDto> goodsList = cmsCouponSpecMapper.getGoodsList(cmsCouponSpecDto);
            return goodsList;
    }

    @Override
    public void deleteBoundGoods(Long specId) {
        cmsCouponSpecMapper.deleteBoundGoods(specId);
    }



    @Override
    public void deleteBoundGoodsList(List<Long> list) {
        cmsCouponSpecMapper.deleteBoundGoodsList(list);
    }


    @Override
    public List<CmsCouponGoodsDto> getCouponGoodsByCouponId(Long couponId){
        return cmsCouponSpecMapper.getCouponGoodsByCouponId(couponId);
    }
}
